package com.article.service.Impl;

import com.article.entity.dto.SearchMemberDao;
import com.article.entity.pojo.Member;
import com.article.entity.vo.MemberVo;
import com.article.mapper.MemberMapper;
import com.article.service.MemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
@Slf4j
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public MemberVo search(SearchMemberDao searchMemberDao) {
        List<Member> admin = memberMapper.getMemberPage(searchMemberDao);
        MemberVo adminPage = new MemberVo();
        adminPage.setList(admin);
        adminPage.setTotal(memberMapper.getMemberPageCount(searchMemberDao.getSearch()));
        return adminPage;
    }

    @Override
    public void add(Member member) {
        member.setIntodata(LocalDate.now());
        memberMapper.insert(member);
    }

    @Override
    public void delete(Long id) {
        memberMapper.deleteById(id);
    }

    @Override
    public void deletes(Long[] ids) {
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("id", ids);
        memberMapper.delete(queryWrapper);
    }


}
